home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / Collision][ demo ƒ / sApple.p < prev    next >
Text File  |  1995-01-16  |  2KB  |  103 lines

  1. { Apple sprite for SATcollision][ }
  2. { No, it has nothing to do with old Apple computers :-) }
  3.  
  4. unit sApple;
  5.  
  6. interface
  7.  
  8.     uses
  9. {$ifc UNDEFINED THINK_PASCAL}
  10.         Types, QuickDraw, {}
  11. {$endc}
  12.         SAT;
  13.  
  14.     var
  15.         nammSound, bliaehSound: Handle;
  16.         goodFace, badFace: FacePtr;
  17.         coreDump: FacePtr;
  18.  
  19.     procedure InitApple;
  20.     procedure SetupApple (me: SpritePtr);
  21.     procedure HandleApple (me: SpritePtr);
  22.     procedure HitApple (me, him: SpritePtr);
  23.  
  24. implementation
  25.  
  26.     procedure InitApple;
  27.         var
  28.             i: integer;
  29.     begin
  30.         nammSound := SATGetNamedSound('namm');
  31.         bliaehSound := SATGetNamedSound('bliaeh');
  32.         goodFace := SATGetFace(132);
  33.         badFace := SATGetFace(133);
  34.         coreDump := SATGetFace(135);
  35.     end;
  36.  
  37.     procedure SetupApple (me: SpritePtr);
  38.     begin
  39.         me^.speed.h := 1 + SATRand(3);
  40.         me^.kind := -2; {Enemy kind}
  41.         me^.face := GoodFace;
  42.         SetRect(me^.hotRect, 0, 0, 32, 32);
  43.         me^.task := @HandleApple;
  44.         me^.hitTask := @HitApple;
  45.     end;
  46.  
  47. {We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.}
  48. {Note that the "kind" field is not modified my SAT since we are not using KindCollision!}
  49.  
  50.     procedure HandleApple (me: SpritePtr);
  51.     begin
  52.  
  53.         case me^.kind of
  54.             -2: 
  55.                 me^.face := goodFace;
  56.             -3: 
  57.                 me^.face := badFace;
  58.         end;
  59.  
  60.         me^.position.h := me^.position.h + me^.speed.h;
  61.         if me^.position.h > gSAT.offSizeH - 16 then
  62.             begin
  63.                 me^.speed.h := -1 - SATRand(3);
  64.                 if SATRand(2) = 0 then
  65.                     me^.kind := -3
  66.                 else
  67.                     me^.kind := -2;
  68.             end;
  69.         if me^.position.h < -16 then
  70.             begin
  71.                 me^.speed.h := 1 + SATRand(3);
  72.                 if SATRand(2) = 0 then
  73.                     me^.kind := -3
  74.                 else
  75.                     me^.kind := -2;
  76.             end;
  77.     end;
  78.  
  79.     procedure HitApple;
  80.     begin
  81.         if him^.task = @HandleApple then
  82.             me^.kind := -3 {Colliding apples corrupt each other!}
  83.         else
  84. {If "him" is not an apple, then it must be the player!}
  85.             if him^.mode >= 0 then {if the player feels bad, don't eat}
  86.                 case me^.kind of
  87.                     -2: 
  88.                         begin
  89.                             SATSoundPlay(nammSound, 1, false);
  90.                             me^.task := nil;
  91.                             him^.mode := 25;
  92.                             SATPlotFace(coreDump, nil, me^.position, true);
  93.                         end;
  94.                     -3: {Bad apple, make player feel bad.}
  95.                         begin
  96.                             him^.mode := -20;
  97.                             SATSoundPlay(bliaehSound, 2, false);
  98.                         end;
  99.                     otherwise {This shouldn't happend!}
  100.                 end;
  101.     end;
  102.  
  103. end.